/**
 * Copyright (C) 2013 The yydorid-framework project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.yangying.androidframework.util;

import net.yangying.androidframework.R;
import net.yangying.androidframework.util.handler.DialogHandler;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;

/**
 * @author yangying
 * @date 2013-1-17 上午9:24:06
 * @version 1.0
 *
 */
public class DialogUtil {

    
	/**
	 * 包含确定，取消的对话框
	 * 
	 * @param context
	 * @param msgResId
	 * @param handler
	 */
    public static void showDialog(Context context, int msgResId, final DialogHandler handler) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setMessage(context.getString(msgResId));
        builder.setPositiveButton(context.getString(R.string.dialog_ok), new OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
          handler.onPositiveButton();
          dialog.dismiss();
         }
        });
        builder.setNegativeButton(context.getString(R.string.dialog_cancel), new OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
          handler.onNegativeButton();
          dialog.dismiss();
         }
        });
        builder.setOnCancelListener(new OnCancelListener() {
			
			@Override
			public void onCancel(DialogInterface dialog) {
				handler.onNegativeButton();
			}
		});
        builder.create().show();
  }
    
    public static void show(Context context,int dialogTitleId,int dialogMsgId, final DialogHandler handler){
        Builder b = new AlertDialog.Builder(context).setTitle(context.getString(dialogTitleId)).setMessage(context.getString(dialogMsgId));
        b.setPositiveButton(context.getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            	handler.onPositiveButton();
                }
        }).setNeutralButton(context.getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.cancel();
                handler.onNegativeButton();
            }
        }).setOnCancelListener(new OnCancelListener() {
			
			@Override
			public void onCancel(DialogInterface dialog) {
				handler.onNegativeButton();
			}
		}).show();
    }
}
